package com.lanqiao.attendance.mapper;

import com.lanqiao.attendance.pojo.Teacher;
import com.lanqiao.attendance.vo.LoginParam2;
import com.lanqiao.attendance.vo.TeacherVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * * @Author Pu Yunsheng
 * * @Data 2022/7/9 下午 04:50
 * * @Version 1.0
 **/
@Mapper
public interface TeacherMapper {

    /**
     * 增加
     * @param teacherVo
     * @return
     */
    @Insert("INSERT INTO tb_teacher(tea_account,tea_password,tea_name,tea_sex,tea_age,tea_identify,tea_phone," +
            "tea_email,tea_location,tea_level,tea_role,tea_createTime,tea_updateTime)" +
            "VALUES(#{account},#{password},#{name},#{sex},#{age},#{identify},#{phone}," +
            "#{email},#{location},#{level},#{role},now(),now())")
    public int addTeacher(TeacherVo teacherVo);

    /**
     * 删除
     * @param account
     * @return
     */
    @Delete("DELETE FROM tb_teacher WHERE tea_account = #{account}")
    public int deleteTeacherByNum(String account);

    /**
     * 修改
     * @return
     */
    @Update("UPDATE tb_teacher SET tea_account = #{account}," +
                                "tea_name = #{name}," +
                                "tea_sex = #{sex}," +
                                "tea_age = #{age}," +
                                "tea_identify = #{identify},"+
                                "tea_phone = #{phone}," +
                                "tea_email = #{email}," +
                                "tea_location = #{location}," +
                                "tea_level = #{level}," +
                                "tea_role = #{role},"+
                                "tea_updateTime = now()" +
            "WHERE id = #{id}")
    public int updateTeacher(TeacherVo teacherVo);

    /**
     * 查询(一个)
     * @param account
     * @return
     */
    @Select("SELECT * FROM tb_teacher WHERE tea_account = #{account}")
    @Results(id = "resultMap" , value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "tea_account", property = "account"),
            @Result(column = "tea_password", property = "password"),
            @Result(column = "tea_name", property = "name"),
            @Result(column = "tea_sex", property = "sex"),
            @Result(column = "tea_age", property = "age"),
            @Result(column = "tea_identify", property = "identify"),
            @Result(column = "tea_phone", property = "phone"),
            @Result(column = "tea_email", property = "email"),
            @Result(column = "tea_location", property = "location"),
            @Result(column = "tea_level", property = "level"),
            @Result(column = "tea_role", property = "role"),
            @Result(column = "tea_createTime", property = "createTime"),
            @Result(column = "tea_updateTime", property = "updateTime"),
    })
    public Teacher queryTeacherByNum(String account);

    /**
     * 查询(全部)
     * @return
     */
    @Select("SELECT * FROM tb_teacher t ORDER BY t.tea_createTime desc")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "tea_account", property = "account"),
            @Result(column = "tea_password", property = "password"),
            @Result(column = "tea_name", property = "name"),
            @Result(column = "tea_sex", property = "sex"),
            @Result(column = "tea_age", property = "age"),
            @Result(column = "tea_identify", property = "identify"),
            @Result(column = "tea_phone", property = "phone"),
            @Result(column = "tea_email", property = "email"),
            @Result(column = "tea_location", property = "location"),
            @Result(column = "tea_level", property = "level"),
            @Result(column = "tea_role", property = "role"),
            @Result(column = "tea_createTime", property = "createTime"),
            @Result(column = "tea_updateTime", property = "updateTime"),

    })
    public List<Teacher> queryAllTeacher();

    /**
     * 查询(登录)
     * @param login
     * @return
     */
    @Select("SELECT * FROM tb_teacher WHERE tea_account = #{account} and tea_password = #{password}")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "tea_account", property = "account"),
            @Result(column = "tea_password", property = "password"),
            @Result(column = "tea_name", property = "name"),
            @Result(column = "tea_sex", property = "sex"),
            @Result(column = "tea_age", property = "age"),
            @Result(column = "tea_identify", property = "identify"),
            @Result(column = "tea_phone", property = "phone"),
            @Result(column = "tea_email", property = "email"),
            @Result(column = "tea_location", property = "location"),
            @Result(column = "tea_level", property = "level"),
            @Result(column = "tea_role", property = "role"),
            @Result(column = "tea_createTime", property = "createTime"),
            @Result(column = "tea_updateTime", property = "updateTime"),
    })
    public Teacher login(LoginParam2 login);


    Teacher queryByAccountAndPwd(String account, String password);

    /**
     * 分页查询
     * @param start
     * @param size
     * @return
     */
    @Select("SELECT * FROM tb_teacher LIMIT #{start},#{size}")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "tea_account", property = "account"),
            @Result(column = "tea_password", property = "password"),
            @Result(column = "tea_name", property = "name"),
            @Result(column = "tea_sex", property = "sex"),
            @Result(column = "tea_age", property = "age"),
            @Result(column = "tea_identify", property = "identify"),
            @Result(column = "tea_phone", property = "phone"),
            @Result(column = "tea_email", property = "email"),
            @Result(column = "tea_location", property = "location"),
            @Result(column = "tea_level", property = "level"),
            @Result(column = "tea_role", property = "role"),
            @Result(column = "tea_createTime", property = "createTime"),
            @Result(column = "tea_updateTime", property = "updateTime"),
    })
    public List<Teacher> pageQuery(@Param("start") Integer start,
                                     @Param("size") Integer size);


}
